//
//  CinemaListViewController.m
//  豆瓣(阿黄)
//
//  Created by dllo on 15/10/27.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "CinemaListViewController.h"
#import "CinemaListTableViewCell.h"
#import "AppTools.h"
#import "CinemaList.h"

@interface CinemaListViewController ()<UITableViewDataSource, UITableViewDelegate>

//@property (nonatomic, retain)NSMutableDictionary *bigDic;

@property (nonatomic, retain)NSMutableArray *cinemaArray;

@end

@implementation CinemaListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"影院";
    
    [self.view addSubview:self.cinemaTableView];
    [self.cinemaTableView release];
    
    [self.cinemaTableView registerClass:[CinemaListTableViewCell class] forCellReuseIdentifier:@"cinemaCell"];
    
    self.cinemaTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    
    [AppTools getDataWithURLStr:@"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/cinemalist.php" Block:^(id consequnce) {
        self.cinemaArray = [NSMutableArray array];
        NSMutableDictionary *bigDic = consequnce;
//        NSLog(@"-----%@",bigDic);
        NSMutableDictionary *dic = [bigDic objectForKey:@"result"];
//        NSLog(@"222222%@",dic);
        NSMutableArray *array = [dic objectForKey:@"data"];
//        NSLog(@"1111111%@",array);
        for (NSMutableDictionary *littleDic in array) {
            CinemaList *cinemaL = [[CinemaList alloc] init];
            [cinemaL setValuesForKeysWithDictionary:littleDic];
            [self.cinemaArray addObject:cinemaL];
            [cinemaL release];
        }
        NSLog(@"%@",self.cinemaArray);
        [self.cinemaTableView reloadData];
    }];
}


-(UITableView *)cinemaTableView{

    if (_cinemaTableView == nil) {
        self.cinemaTableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewStylePlain];
        self.cinemaTableView.delegate = self;
        self.cinemaTableView.dataSource = self;
    }
    return _cinemaTableView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 150;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return self.cinemaArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *cellID = @"cinemaCell";
    CinemaListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    
    CinemaList *cinemaL = [self.cinemaArray objectAtIndex:indexPath.row];
//    NSLog(@"%@",self.cinemaArray);
    [cell sendValue:cinemaL];
    
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
